<template>
  <v-table
    :pageSize="pageSize"
    :page="page"
    :tableConfig="tableConfig"
    :tableData="tableData"
    :total="total"
    :style="{height:calcHeight(340) + 'px'}"
    @findData="getTableData"
    @getTableData="getTableData"
    @searhData="setSearhData"
    @selectData="setSelectData"
    @setdialog="setdialog"
    @upData="getTableData"
    ref="table"
  ></v-table>
</template>

<script>
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import bus from "@/bus/bus";

export default {
  name: "Table",
  mixins: [baseMixin],
  props: {
    data: {
      type: Object,
    },
  },
  data() {
    return {
      tableConfig: [
        {
          label: this.$t('outbound.userlinenumber'),
          prop: "receiptlinenumber",
          input: "input",
          disabled: false,
          width: "60px",
        },
        { label: this.$t('config.shipper'), prop: "storerkey", input: "input", disabled: false },
        {
          label: this.$t('config.sku'),
          prop: "sku",
          input: "input",
          disabled: false,
        },
        { label: this.$t('common.desc'), prop: "descr" },
        {
          label: this.$t('config.packaging'),
          prop: "packkey",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t('config.measureUnit'),
          prop: "uom",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t('in.lpn'),
          prop: "toid",
          input: "input",
          disabled: false,
          /*eidtFlag: true,
          verify(value, that) {
            value = value.replace(/\s*!/g, "");
            if (value === "") {
              that.$message.error(`LPN不能为空`);
              return false;
            } else {
              return true;
            }
          },*/
        },
        {
          label: this.$t('config.loc'),
          prop: "toloc",
          input: "input",
          disabled: false,
          /*eidtFlag: true,
          verify(value, that) {
            value = value.replace(/\s*!/g, "");
            if (value === "") {
              that.$message.error(`库位不能为空`);
              return false;
            } else {
              return true;
            }
          },*/
        },
        {
          label: "PO/SO",
          prop: "pokey",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t('common.status'),
          prop: "status",
          input: "select",
          disabled: false,
          options: this.getOptions("codelkup/RECSTATUS"),
        },
        {
          label: this.$t('in.totalqtyexpected'),
          prop: "qtyexpected",
          input: "input",
        },
        {
          label: this.$t('in.qtyreceived'),
          prop: "qtyreceived",
          input: "input",
          disabled: false,
          /*eidtFlag: true,
          verify(value, that) {
            if (value === "") {
              that.$message.error(`接收量不能为空`);
              return false;
            } else {
              var re = /^[0-9]*$/;
              let te = value;
              let flag = re.test(te);
              if (flag) {
                if (value < 0) {
                  that.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
                  return false;
                } else {
                  return true;
                }
              } else {
                that.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
                return false;
              }
            }
          },*/
        },
      ],
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 10,
      searhData: {},
      editFlag: true,
    };
  },
  methods: {
    //获取table数据
    async getTableData(page, data) {
      try {
        let res = await this.$api.post(`/detail/queryListOfDark/${page}`, {
          receiptkey: this.data.argument.receiptkey,
          ...data,
        });
        
          this.loading = false;
          this.tableData = res.page.list;
          this.page = res.page.curPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
      } catch (e) {
        this.$message.error(e);
      }
    },
    //搜索值
    setSearhData(data, up) {
      if (!up) {
        this.searhData = data;
      } else {
        this.searhData = data;
        this.getTableData(1, this.searhData);
      }
    },
    //选中的数据
    setSelectData(data) {
      this.$parent.setSelectData(data);
    },
    //进入详情
    async setdialog(data) {
      this.$parent.setdialog(data);
    },
  },
  mounted() {

    bus.$on("asn.DetailList.Table.getTableData", msg => {
      this.getTableData(1, {});
    });
    this.getTableData(1, {});
  },
  components: {
    "v-table": table,
  },
};
</script>

<style scoped></style>
